from shapely.geometry import Point
def get_color_for_unit_count(unit_count: int, max_unit_count: int = 10) -> str:
if unit_count == 1:
return "#FF0000" # red
# For unit_count > 1: magenta to white gradient
scale = min(unit_count, max_unit_count) / max_unit_count
green_value = int(255 * scale) # from 0 (magenta) to 255 (white)
return f"#FF{green_value:02X}FF"
for _, row in data["Addresses_in_fan"].iterrows():
pt = row.geometry
# Skip labels for addresses where UnitType is not None.
unit_type = row["UnitType"]
if unit_type is not None:
continue
# Only plot if geometry is a valid Point
if not isinstance(pt, Point):
print(f"Skipping non-Point geometry at index {_}: {type(pt)}")
continue
if (row.get("BuildingNumber")=="1465") and (row.get("StreetName")=="Floyd"):
#logger.debug( row )
pass
unit_count = row.get("UnitCount",1)
label = row.get("AddressLabel", "")
if unit_count>1:
label = label + f" ({unit_count})"
tooltip = folium.Tooltip(label) if label.strip() else None
color = get_color_for_unit_count(unit_count)
folium.CircleMarker(
location=[pt.y, pt.x],
radius=2,
color=color,
fill=True,
fill_opacity=0.8,
tooltip=tooltip, # Explicit safe wrapper
).add_to(m)
# Add layer control and display map
x = folium.LayerControl().add_to(m)